package com.haoniu.web.controller.module;

import com.haoniu.framework.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.haoniu.common.annotation.Log;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.module.domain.database.PlayRules;
import com.haoniu.module.service.PlayRulesService;
import com.haoniu.web.core.base.BaseController;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.common.base.AjaxResult;

import java.util.List;
/**
 * 玩法说明 信息操作处理
 *
 * @author houyijun
 * @date 2019-01-25
 */
@Controller
@RequestMapping("/module/playRules")
public class PlayRulesController extends BaseController
{
    private String prefix = "module/playRules";

	@Autowired
	private PlayRulesService playRulesService;

	@RequiresPermissions("module:playRules:view")
	@GetMapping()
	public String playRules()
	{
	    return prefix + "/playRules";
	}

	/**
	 * 查询玩法说明列表
	 */
	@RequiresPermissions("module:playRules:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(PlayRules playRules) {
		startPage();
        List<PlayRules> list = playRulesService.selectPlayRulesList(playRules);
		return getDataTable(list);
	}

	/**
	 * 新增玩法说明
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存玩法说明
	 */
	@RequiresPermissions("module:playRules:add")
	@Log(title = "玩法说明", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(PlayRules playRules) {
        playRules.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(playRulesService.insertPlayRules(playRules));
	}

	/**
	 * 修改玩法说明
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		PlayRules playRules = playRulesService.selectPlayRulesById(id);
		mmap.put("playRules", playRules);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存玩法说明
	 */
	@RequiresPermissions("module:playRules:edit")
	@Log(title = "玩法说明", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(PlayRules playRules) {
        playRules.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(playRulesService.updatePlayRules(playRules));
	}

	/**
	 * 删除玩法说明
	 */
	@RequiresPermissions("module:playRules:remove")
	@Log(title = "玩法说明", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(playRulesService.deletePlayRulesByIds(ids));
	}

}
